package com.singularity.onelabel;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.RadioGroup;

import com.singularity.onelabel.capsule.CapsuleFragment;
import com.singularity.onelabel.goal.GoalFragment;
import com.singularity.onelabel.lable.LabelFragment;
import com.singularity.onelabel.settings.SettingFragment;
import com.singularity.onelabel.utils.HomeTabSelectUtils;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    // 声明一个RadioGroup，RadioGroup 是个容器控件，里面存放的是RadioButton
    private RadioGroup homeBottomGroup;
    // 声明一个列表，存放Fragment.
    private List<Fragment> fragmentList = new ArrayList<>();
    private WeakReference<MainActivity> weakReference = new WeakReference<MainActivity>(MainActivity.this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }


    private void initView() {
        //初始化RadioGroup
        homeBottomGroup = findViewById(R.id.bottom_tab_layout);
        // 创建首页四个页面的Fragment，用于进行切换。
        fragmentList.add(new LabelFragment());
        fragmentList.add(new CapsuleFragment());
        fragmentList.add(new GoalFragment());
        fragmentList.add(new SettingFragment());
        // 获得Fragment的管理者类
        FragmentManager fm = getSupportFragmentManager();
        // 设置首页RadioGroupa的item的选中时候页面的切换和item的样式
        HomeTabSelectUtils selectUtils = new HomeTabSelectUtils(weakReference.get(),homeBottomGroup,fragmentList,R.id.container_layout,fm);

    }
}
